import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class demo2 {
    //超出时间范围
    public int halveArray1(int[] nums) {
        int n=nums.length;
        float []arr=new float[n];
       float sum=0;
        for (int i = 0; i < n; i++) {
            arr[i]=nums[i];
            sum+=nums[i];
        }
        float ret=0;
        int x=0;
        while (ret<(float)(sum/2)){
            Arrays.sort(arr);
            ret+=arr[n-1]/2;
            arr[n-1]=arr[n-1]/2;
            x++;
        }
        return x;
    }
    public int halveArray(int[] nums) {
        PriorityQueue priorityQueue=new PriorityQueue<Double>((a,b)-> b.compareTo(a));
        int n=nums.length;
        Double s=0.0;
        for (int i = 0; i <n; i++) {
            Double x=(double)nums[i];
            priorityQueue.offer(x);
            s+=nums[i];
        }
        Double sum=0.0;
        int ret=0;
        while (sum<s/2){
            Double temp= (double) priorityQueue.peek()/2;
            sum+=temp;
            priorityQueue.poll();
            priorityQueue.offer(temp);
            ret++;
        }
        return ret;
    }

}
